@ mutex_unlock.S: mutex_unlock sycall wrapper
@
@ Authors: Nora Tarano   ntarano@andrew.cmu.edu
@          Yuan Meng     yuanm@andrew.cmu.edu
@          Yipeng Yun    yipengy@andrew.cmu.edu
@ Date:    Dec 11, 2011

#include <asm.h>
#include <bits/swi.h>

	.file "mutex_unlock.S"

FUNC(mutex_unlock)
	swi		MUTEX_UNLOCK
	cmp		r0, #0
	blt		_set_errno	@ if ret < 0, set errno appropriately
	b		_mutex_unlock_end

_set_errno:
	rsb		r0, r0, #0	@ negate return value
	str		r1, [sp]    @ save r1
	ldr		r1, =errno	@ load address of errno
	str		r0, [r1]	@ errno = abs(ret)
	ldr		r1, [sp]    @ restore r1
	mov		r0, #-1		@ set r0 = -1 (error)

_mutex_unlock_end:
	mov		pc, lr		@ return to caller
